package com.woniu.liuzhougov.fileManage.util;

import org.springframework.core.io.Resource;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * @description: 获取目录工具类
 * @author: Arvin
 * @create: 2019-05-05 12:59
 **/
public class GetServerRealPathUnit {

    public static String getPath(String subdirectory){
        //获取目录
        File upload = null;
        try {
            //获取根目录
            File path  = new File(ResourceUtils.getURL("classPath:").getPath());
            if (!path.exists()){
                path = new File("");
            }
            //获取需要的目录
            upload = new File(path.getAbsolutePath(),subdirectory);
            if (!upload.exists()){
                upload.mkdirs();
            }
            String realPath = upload +"";
            return realPath;
        } catch (FileNotFoundException e) {
            throw new RuntimeException("获取服务器路径错误...");
        }
    }
}
